#include <iostream>
#include <thread>
#include <future>
#include <chrono>
using namespace std;
using namespace std::this_thread;
using namespace std::chrono;

#include "yolo.h"
#include <opencv2/opencv.hpp>
using namespace cv;
int main(int argc, char **argv)
{
    // string strConfig = argv[1];
    // string strWeight = argv[2];
    string strImg = argv[3];

    // cout << strConfig << endl;
    // cout << strWeight << endl;
    cout << strImg << endl;

    // Yolo y;
    // y.setConfigFilePath((char *)strConfig.c_str());
    // y.setWeightFilePath((char *)strWeight.c_str());
    Yolo yolo;
    yolo.setConfigFilePath("cfg/yolo.cfg");
    yolo.setDataFilePath("cfg/coco.data");
    yolo.setWeightFilePath("yolo.weights");
    yolo.setAlphabetPath("data/labels/");
    yolo.setNameListFile("data/coco.names");

    Mat img = imread("data/dog.jpg");
    //    imshow("xx", mat);
    //    waitKey(0);
    vector<DetectedObject> detection;
    yolo.detect(img, detection);

    for (int i = 0; i < detection.size(); i++)
    {
        DetectedObject &o = detection[i];
//        cv::rectangle(img, o.bounding_box, cv::Scalar(255, 0, 0), 2);

        const char *class_name = yolo.getNames()[o.object_class];
        cout << class_name << endl;

        char str[255];
        //sprintf(str,"%s %f", names[o.object_class], o.prob);
        sprintf(str, "%s", class_name);
//        cv::putText(img, str, cv::Point2f(o.bounding_box.x, o.bounding_box.y), cv::FONT_HERSHEY_SIMPLEX, 0.6, cv::Scalar(0, 0, 255), 2);

        //                if( strcmp(class_name,"person") == 0)
        //                {
        //                    std::ostringstream oss;
        //                    oss << frame_no << delimiter
        //                        << o.bounding_box.x << delimiter
        //                        << o.bounding_box.y << delimiter
        //                        << o.bounding_box.width << delimiter
        //                        << o.bounding_box.height;
        //                    file << oss.str().c_str() << std::endl;
        //                }
    }

//    cv::imshow("yolo++ demo", img);
//    cv::waitKey(0);
    // y.detect(mat, detection);

    return 0;
}
